/*
============================================================================
 Name        : dd_define.h
 Author      : Jian (raphyer@hotmail.com)
 Version     :
 Copyright   : GPL
 Description : dd_define.h - header file
============================================================================
*/

#ifndef DD_DEFINE_H
#define DD_DEFINE_H

#include "dd_macro.h"
#include "dd_error.h"

/*
 * Base type definition 
*/
#define DD_BYTE		unsigned char
#define DD_UTF8		unsigned char
#define DD_WCHAR    unsigned short
#define DD_UINT		unsigned int

#define DD_BOOL		int 
#define DD_TRUE		1
#define DD_FALSE	0

typedef int dd_sync_tag[2] ;

typedef void sd_file ;
typedef void sd_audio ;
typedef void sd_semp ;
typedef void sd_rlock ;
typedef void sd_socket ;
typedef void sd_timer ;
typedef void sd_thread ;

#define dd_stag_set(d, v1, v2)   do { (*d)[0] = v1; (*d)[1] = v2;} while (0)
#define dd_stag_is_equal(d1, d2) ((*d1)[0] == (*d2)[0] && (*d1)[1] == (*d2)[1])

#ifdef __ANDROIDOS__

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <limits.h>

#define dd_malloc		malloc
#define dd_free			free

#define __dd_inline	

#define __likely(x)       __builtin_expect((x),1)
#define __unlikely(x)     __builtin_expect((x),0)

#elif defined(__SYMBIAN32__)

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <limits.h>

#define dd_malloc		malloc
#define dd_free			free

#define __dd_inline	

#define __likely(x)     (x)
#define __unlikely(x)   (x)

#elif defined(WIN32)

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <limits.h>

/* For VS2003 disable some warnings */
#pragma warning (disable : 4311)
#pragma warning (disable : 4312)


#define dd_malloc		malloc
#define dd_free			free

#define __dd_inline	

#define __likely(x)     (x)
#define __unlikely(x)   (x)

#endif

#define dd_destroy(d)   do { if (__likely(d)) dd_free(d) ; d = NULL ; } while(0)

#define dd_strcasecmp   strcasecmp

#define dd_min(a,b)		((a) < (b) ? (a) : (b)) 
#define dd_max(a,b)		((a) > (b) ? (a) : (b)) 
#define dd_abs(n)       ((((int)(n)) < 0) ? (-((int)(n))) : (int)(n))

#define dd_covert_endian32(d) ((DD_UINT)((DD_BYTE*)(d))[0] << 24 | ((DD_UINT)((DD_BYTE*)(d))[1] << 16) | \
    ((DD_UINT)((DD_BYTE*)(d))[2] << 8) | ((DD_UINT)((DD_BYTE*)(d))[3]))


#ifdef __DD_DEBUG
#define __Log_File_Line		{ dd_log_error("Assert in file = %s and line = %d", __FILE__, __LINE__); }
#define __Panic_File_Line	{ } 
#else 
#define __Log_File_Line		{ }
#define __Panic_File_Line	{ }
#endif	

#define __DD_ASSERT(c)              do { if(__unlikely(!((c)))) { __Log_File_Line; __Panic_File_Line;} } while(0)
#define __DD_ASSERT_DEFENSE(c,d)    do { if(__unlikely(!((c)))) { __Log_File_Line; __Panic_File_Line; {d;};} } while(0)

#define __DD_CHECK_MEM(p, s, d)     do { if(__unlikely(p == NULL)) { dd_log_error("malloc memory size: %d empty in %s, %d", s, __FILE__, __LINE__); d; } else { memset(p, 0, s) ; } } while (0)

#ifdef __DD_LOG
#define DD_DEFAULT_LOG_PRIORITY  DD_LOG_PRIORITY_TRACE
#endif

#ifdef  __cplusplus
#define __DD_BEGIN_DECLS  extern "C" {
#define __DD_END_DECLS    }
#else
#define __DD_BEGIN_DECLS
#define __DD_END_DECLS
#endif


#endif	/* DD_DEFINE_H */

/* End of File */
